package com.example.mobile2121606110syc0512homework;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity {

    private TextView tvMainTitle2;
    private RadioGroup radioGroup;
    private Button btnMainBuy;
    private CheckBox checkBox;
    private CheckBox checkBox2;
    private CheckBox checkBox3;
    private CheckBox checkBox4;
    private CheckBox checkBox5;
    private CheckBox checkBox6;
    private CheckBox checkBox7;
    private CheckBox checkBox8;
    private CheckBox checkBox9;
    private CheckBox checkBox10;
    private CheckBox checkBox11;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        btnMainBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String radBtnId = "";
                if (checkBox.isChecked()==true){
                    radBtnId+=checkBox.getText().toString()+"\n";
                }
                if (checkBox2.isChecked()==true){
                    radBtnId+=checkBox2.getText().toString()+"\n";
                }
                if (checkBox3.isChecked()==true){
                    radBtnId+=checkBox3.getText().toString()+"\n";
                }
                if (checkBox4.isChecked()==true){
                    radBtnId+=checkBox4.getText().toString()+"\n";
                }
                if (checkBox5.isChecked()==true){
                    radBtnId+=checkBox5.getText().toString()+"\n";
                }
                if (checkBox6.isChecked()==true){
                    radBtnId+=checkBox6.getText().toString()+"\n";
                }
                if (checkBox7.isChecked()==true){
                    radBtnId+=checkBox7.getText().toString()+"\n";
                }
                if (checkBox8.isChecked()==true){
                    radBtnId+=checkBox8.getText().toString()+"\n";
                }
                if (checkBox9.isChecked()==true){
                    radBtnId+=checkBox9.getText().toString()+"\n";
                }
                if (checkBox10.isChecked()==true){
                    radBtnId+=checkBox10.getText().toString()+"\n";
                }
                if (checkBox11.isChecked()==true){
                    radBtnId+=checkBox11.getText().toString()+"\n";
                }

                if (radBtnId!=""){
                    Intent intent = new Intent();
                    intent.putExtra("goods", radBtnId);
                    setResult(RESULT_OK, intent);
                    finish();
                }else {
                    new AlertDialog.Builder(MainActivity2.this)
                            .setMessage("请选择原材料")
                            .setPositiveButton("确定", null)
                            .create()
                            .show();
                }


            }
        });
    }

    private void initView() {
        tvMainTitle2 = (TextView) findViewById(R.id.tvMainTitle2);
        btnMainBuy = (Button) findViewById(R.id.btnMainBuy);
        checkBox = (CheckBox) findViewById(R.id.checkBox);
        checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
        checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
        checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
        checkBox5 = (CheckBox) findViewById(R.id.checkBox5);
        checkBox6 = (CheckBox) findViewById(R.id.checkBox6);
        checkBox7 = (CheckBox) findViewById(R.id.checkBox7);
        checkBox8 = (CheckBox) findViewById(R.id.checkBox8);
        checkBox9 = (CheckBox) findViewById(R.id.checkBox9);
        checkBox10 = (CheckBox) findViewById(R.id.checkBox10);
        checkBox11 = (CheckBox) findViewById(R.id.checkBox11);
    }
}